<?xml version="1.0" encoding="UTF-8"?>
<!-- 
	Copyright (c) 2012 Mia-Software. All rights reserved. This program and 
	the accompanying materials are made available under the terms of the Eclipse 
	Public License v1.0 which accompanies this distribution, and is available 
	at http://www.eclipse.org/legal/epl-v10.html 
	
	Contributors: 
		Herve ESTEGUET (Mia-Software) - Bug 381352 - [Releng] There must be a project to configure the build by tycho 
-->
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common"
	extension-element-prefixes="exsl" xmlns:m2="http://maven.apache.org/POM/4.0.0">
	<xsl:output indent="yes" />

	<xsl:param name="WORKSPACE" />
	<xsl:param name="relengDir" />

	<xsl:template match="/">
		<project
			xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
			xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<xsl:apply-templates select="//m2:project/*[name()!='build']" />
			<build>
				<plugins>
					<!-- In case there were others plugins configurations -->
					<xsl:apply-templates select="//m2:project/m2:build/m2:plugins/*" />
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-antrun-plugin</artifactId>
						<version>1.7</version>
						<executions>
							<execution>
								<id>generate-api-use-report</id>
								<phase>package</phase>
								<goals>
									<goal>run</goal>
								</goals>
								<configuration>
									<target>
										<property name="maven.plugin.classpath" refid="maven.plugin.classpath" />
										<property name="maven.compile.classpath" refid="maven.compile.classpath" />
										<property name="WORKSPACE"><xsl:value-of select="$WORKSPACE" /></property>
										<property name="releng.dir"><xsl:value-of select="$relengDir" /></property>
										<xsl:comment>
											We launch the API use computation
										</xsl:comment>
										<xsl:element name="ant">
											<xsl:attribute name="antfile">
												<xsl:value-of select="concat($relengDir, '/apiuse/api-use-build.xml')" />
											</xsl:attribute>
											<xsl:attribute name="target">launchApiAnalysis</xsl:attribute>
											<xsl:attribute name="inheritRefs">true</xsl:attribute>
										</xsl:element>
									</target>
								</configuration>
							</execution>
							<execution>
								<id>register-api-use-report</id>
								<phase>package</phase>
								<goals>
									<goal>run</goal>
								</goals>
								<configuration>
									<target>
										<property name="WORKSPACE"><xsl:value-of select="$WORKSPACE" /></property>
										<property name="releng.dir"><xsl:value-of select="$relengDir" /></property>
										<xsl:element name="ant">
											<xsl:attribute name="antfile">
												<xsl:value-of select="concat($relengDir, '/ant-scripts.xml')" />
											</xsl:attribute>
											<xsl:attribute name="target">register-apiuse-report</xsl:attribute>
											<xsl:attribute name="inheritRefs">true</xsl:attribute>
										</xsl:element>
										<xsl:element name="ant">
											<xsl:attribute name="antfile">
												<xsl:value-of select="concat($relengDir, '/ant-scripts.xml')" />
											</xsl:attribute>
											<xsl:attribute name="target">rebuild-update-site</xsl:attribute>
											<xsl:attribute name="inheritRefs">true</xsl:attribute>
										</xsl:element>
										<xsl:element name="ant">
											<xsl:attribute name="antfile">
												<xsl:value-of select="concat($relengDir, '/ant-scripts.xml')" />
											</xsl:attribute>
											<xsl:attribute name="target">create-or-update-final-artifact</xsl:attribute>
											<xsl:attribute name="inheritRefs">true</xsl:attribute>
										</xsl:element>
									</target>
								</configuration>
							</execution>
						</executions>
						<dependencies>
							<dependency>
								<groupId>net.sf.saxon</groupId>
								<artifactId>saxon</artifactId>
								<version>8.7</version>
							</dependency>
							<dependency>
								<groupId>net.sf.saxon</groupId>
								<artifactId>saxon-dom</artifactId>
								<version>8.7</version>
							</dependency>
							<dependency>
								<groupId>ant-contrib</groupId>
								<artifactId>ant-contrib</artifactId>
								<version>1.0b3</version>
								<exclusions>
									<exclusion>
										<groupId>ant</groupId>
										<artifactId>ant</artifactId>
									</exclusion>
								</exclusions>
							</dependency>
						</dependencies>
					</plugin>
				</plugins>
				<!-- In case of other build configurations -->
				<xsl:apply-templates select="//m2:project/m2:build/*[name()!='plugins']" />
			</build>
		</project>
	</xsl:template>

	<xsl:template match="m2:*[name()!='build']|@*">
		<xsl:copy-of select="." />
	</xsl:template>

</xsl:stylesheet>
